package com.yt.generator.engine.base;

import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.yt.generator.engine.config.*;
import com.yt.generator.engine.config.*;
import lombok.Data;

/**
 * 模板生成父类
 *
 * @author fengshuonan
 * @date 2017-05-08 20:17
 */
@Data
public class AbstractTemplateEngine {

    protected ContextConfig contextConfig;                            //全局配置
    protected ControllerClientConfig controllerClientConfig;          //控制器的配置
    protected ControllerCmsConfig controllerCmsConfig;                //控制器的配置
    protected ModelsConfig modelsConfig;                  //models配置
    protected ServiceConfig serviceConfig;                //Service配置
    protected ServiceImplConfig serviceImplConfig;        //ServiceImpl配置
    protected MapperConfig mapperConfig;                  //mapper配置
    protected SqlConfig sqlConfig;                        //sql配置
    protected TableInfo tableInfo;                        //表的信息

    public void initConfig() {
        if (this.contextConfig == null) {
            this.contextConfig = new ContextConfig();
        }
        if (this.controllerClientConfig == null) {
            this.controllerClientConfig = new ControllerClientConfig();
        }
        if (this.controllerCmsConfig == null) {
            this.controllerCmsConfig = new ControllerCmsConfig();
        }

        if (this.serviceConfig == null) {
            this.serviceConfig = new ServiceConfig();
        }
        if (this.serviceImplConfig == null) {
            this.serviceImplConfig = new ServiceImplConfig();
        }

        if (this.mapperConfig == null) {
            this.mapperConfig = new MapperConfig();
        }

        if (this.modelsConfig == null) {
            this.modelsConfig = new ModelsConfig();
        }


        if (this.sqlConfig == null) {
            this.sqlConfig = new SqlConfig();
        }

        this.controllerClientConfig.setContextConfig(this.contextConfig);
        this.controllerClientConfig.init();

        this.controllerCmsConfig.setContextConfig(this.contextConfig);
        this.controllerCmsConfig.init();

        this.serviceConfig.setContextConfig(this.contextConfig);
        this.serviceConfig.init();

        this.serviceImplConfig.setContextConfig(this.contextConfig);
        this.serviceImplConfig.init();

        this.mapperConfig.setContextConfig(this.contextConfig);
        this.mapperConfig.init();

        this.modelsConfig.setContextConfig(this.contextConfig);
        this.modelsConfig.init();

        //this.sqlConfig.setContextConfig(this.contextConfig);
        //this.sqlConfig.init();
    }
}

